// @document https://testfund.10jqka.com.cn/public/whw/kingfisher-temp/dist/#/usage/build-config

// @ts-ignore
export default defineBuildConfig({
  web: {
    mpa: true,
  },
  importOnDemand: [
    {
      // tsconfig配置别名以获取提示，还需要设置alias
      libraryName: 'importTest',
      // {buildTarget}占位符，会编译成hummer/web，不设置libraryDirectory默认为lib/{buildTarget}
      libraryDirectory: '{buildTarget}',
      // 效果与上方一致
      // customName(buildTarget: 'web' | 'hummer') {
      //   return buildTarget;
      // },
    },
  ],
  publicPath: process.env.VUE_APP_BASE_URL,
  onGetWebpackChain(chain) {
    // 别名
    // 排除node_modules中的依赖
    chain.externals({
      vue: 'Vue',
    });
    // 公共部分打包抽离
    chain.optimization.splitChunks({
      cacheGroups: {
        common: {
          name: 'chunk-common',
          chunks: 'initial',
          minChunks: 2,
          maxInitialRequests: 5,
          minSize: 0,
          priority: 1,
          reuseExistingChunk: true,
        },
        vendors: {
          name: 'chunk-vendors',
          test: /[\\/]node_modules[\\/]/,
          chunks: 'initial',
          priority: 2,
          reuseExistingChunk: true,
          enforce: true,
        },
      },
    });
  },
  devServer: {
    open: false,
    host: 'dev.10jqka.com.cn',
    // host: '192.168.137.103',
    disableHostCheck: true,
    port: 8080,
    https: true,
    allowHosts: ['dev.10jqka.com.cn'],
    // 接口代理配置
    proxy: {
      '/api': {
        target: 'https://testm.10jqka.com.cn',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/api': '',
        },
      },
    },
  },

  // 过滤不需要转换 px 的 class
  // selectorBlackList: ['no-vw', 'no-hm'], // 默认 ['no-vw', 'no-hm']，无需担心被覆盖

  monitor: {
    rate: 1,
    pagePath: ["location.hash || '/root'"],
    noTrace: true,
    // serviceVersion: ["getPlatform() + '_1'"],
  },
  outputDir: process.env.NODE_ENV?.includes('PM') ? 'PROGRAM-companyHealthCheck' : 'dist',

  // loader: {
  //   asset: {
  //     maxSize: 10 * 1024, // 10k 默认 8k
  //   },
  //   style: {
  //     preProcessors: ['scss'], // 默认 less
  //   },
  // },

  // babel: {
  //   // includeNodeModules: ['node_modules/@king-fisher'], // 默认，无需特意配置
  //   // excludeNodeModules: ['node_modules'], // 默认，无需特意配置
  // },

  // debug: {
  //   minimize: false, // 是否压缩产物，默认开启
  //   cache: false, // 是否开启换成，默认开启
  //   analyze: true, // 依赖包分析
  // },

  // web: {
  //   mpa: true,
  // },
});
